// src/api.js
import axios from 'axios';

const kimiAPI = axios.create({
    baseURL: import.meta.env.VITE_KIMI_API_URL,
    headers: {
        'Authorization': `Bearer ${import.meta.env.VITE_KIMI_API_KEY}`,
        'Content-Type': 'application/json',
    },
});

let messageslist = [];

export const getChatCompletion = async (message: string) => {
    try {

        messageslist.push({
            role: "user",
            content: message,
        });

        const response = await kimiAPI.post('/chat/completions', {
            model: "moonshot-v1-8k",
            messages: messageslist,

        });
        const datalist = response.data.choices[0].message
        messageslist.push(datalist)
        return datalist.content;
    } catch (error) {
        console.error("API调用出错:", error);
        throw error;
    }
};